# -*- coding: utf-8 -*-
"""
Created on Sun Nov 20 21:42:14 2022

@author: YSL
"""
import os

# 递归遍历目录
def traversal_files(path):
    for dir in os.listdir(path):
        dir = os.path.join(path, dir)
        print(dir)
        # 判断当前目录是否为文件夹
        if os.path.isdir(dir):
            traversal_files(dir)    #递归
        print(dir)

path = 'D:\Machinelearning\yu-shi-long_-home-work'
traversal_files(path)

#%%

def traversal_files(path):
    for root, dirs, files in os.walk(path, topdown=False):
        for name in files:
            print(os.path.join(root, name))
        for name in dirs:
            print(os.path.join(root, name))

path = 'D:\Machinelearning\yu-shi-long_-home-work'
traversal_files(path)